package hung.vnptthanhhoa.cookingbook;
import hung.vnptthanhhoa.adapter.TabsPageAdapter;
import android.app.ActionBar;
import android.app.ActionBar.Tab;
import android.app.FragmentTransaction;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.support.v4.view.ViewPager;

public class Fragment_Main extends FragmentActivity implements
		ActionBar.TabListener {

	private ViewPager viewPager;
	private TabsPageAdapter mAdapter;
	private ActionBar actionBar;

	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);

		viewPager = (ViewPager) findViewById(R.id.pager);
		actionBar = getActionBar();
		mAdapter = new TabsPageAdapter(getSupportFragmentManager());
		viewPager.setAdapter(mAdapter);
		actionBar.setDisplayShowTitleEnabled(false);
		actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);

		Tab tab_nau_an = actionBar.newTab();
		tab_nau_an.setText(R.string.title_nau_an).setTabListener(this);
		actionBar.addTab(tab_nau_an);

		Tab tab_meo_vat = actionBar.newTab();
		tab_meo_vat.setText(R.string.title_meo_vat).setTabListener(this);
		actionBar.addTab(tab_meo_vat);

		Tab tab_suc_khoe = actionBar.newTab();
		tab_suc_khoe.setText(R.string.title_suc_khoe).setTabListener(this);
		actionBar.addTab(tab_suc_khoe);

		Tab tab_dien_dan = actionBar.newTab();
		tab_dien_dan.setText(R.string.title_dien_dan).setTabListener(this);
		actionBar.addTab(tab_dien_dan);
		viewPager.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {

			@Override
			public void onPageSelected(int position) {
				// on changing the page
				// make respected tab selected
				actionBar.setSelectedNavigationItem(position);
			}

			@Override
			public void onPageScrolled(int arg0, float arg1, int arg2) {
			}

			@Override
			public void onPageScrollStateChanged(int arg0) {
			}
		});

	}

	@Override
	public void onTabReselected(Tab arg0, FragmentTransaction arg1) {
		// TODO Auto-generated method stub

	}

	@Override
	public void onTabSelected(Tab tab, FragmentTransaction ft) {
		viewPager.setCurrentItem(tab.getPosition());

	}

	@Override
	public void onTabUnselected(Tab arg0, FragmentTransaction arg1) {
		// TODO Auto-generated method stub

	}


}
